<?php
class Mozg_Paginator
{
    private $perPage;
    private $totalCount;
    private $page;
    private $totalPages = null;

    public function __construct($page = 1, $perPage = 30)
    {
        $this->perPage = $perPage > 0 ? $perPage : 30;
        $this->page = $page > 0 ? $page : 1;
        return $this;
    }

    public function SetTotalCount($totalCount = 0)
    {
        $this->totalCount = $totalCount;
        $this->SetTotalPages();
        return $this;
    }

    private function SetTotalPages()
    {
        $this->totalPages = max(1, ceil($this->totalCount / $this->perPage));
        return $this;
    }

    public function GetSqlLimit ()
    {
        return (($this->page - 1) * $this->perPage) . ", " . $this->perPage;
    }

    public function GetPage()
    {
        return $this->page;
    }

    public function GetTotalCount()
    {
        return $this->totalCount;
    }

    public function GetPerPage()
    {
        return $this->perPage;
    }

    public function GetTotalPages()
    {
        return $this->totalPages;
    }
}